/**
 * pccAcLaboratoryOperFee.js Power by YUI-EXT and JSON.
 * 
 * @author 
 * @email
 */
var pccAcLaboratoryOperFee = { 
	author: "xxx",
	version: "1.0"
};

// -> Action URL
var URL = {
	queryList : 'pccAcLaboratoryOperFeeListProvider.do',
	action : 'pccAcLaboratoryOperFeeAction.do'
};

// -> Primary key
var PK = ["id"];

// -> Column name in Chinese. e.g: CN[1]
var CN = {
	0: "ID",          
	1: "年度",          
	2: "地区",          
	3: "排序",          
	4: "项目",          
	5: "支持方",          
	6: "经费总需求(元/年)"        
};

// -> Column name in English
var EN = {
	0: "id",          
	1: "fiscalYear",          
	2: "fromArea",          
	3: "sortId",          
	4: "projectName",          
	5: "supporters",          
	6: "totalFee",          
	7: "id_old"   
};

// -> Cell width
var WD = {
	0: "10",          
	1: "10",          
	2: "200",          
	3: "10",          
	4: "200",          
	5: "200",          
	6: "10"        
};

// -> Data type e.g: float,int,string
var TY = {
	0: "int",          
	1: "int",          
	2: "string",          
	3: "int",          
	4: "string",          
	5: "string",          
	6: "int"        
};

var storeFields = [	    
	{name: EN[0], type: TY[0]},          
	{name: EN[1], type: TY[1]},          
	{name: EN[2], type: TY[2]},          
	{name: EN[3], type: TY[3]},          
	{name: EN[4], type: TY[4]},          
	{name: EN[5], type: TY[5]},          
	{name: EN[6], type: TY[6]},          
    {name: EN[7], type: TY[0]}   
];

var formFields = [
     {id: EN[0],hidden: true, name: EN[0], fieldLabel:CN[0], xtype: 'numberfield'} 		 
, 
	 {id: EN[1],hidden: true, name: EN[1],hiddenName: EN[1], fieldLabel:CN[1],url: 'parmInfoProvider.do?parmType=FINCAL_YEAR',displayField: 'parmName',valueField: 'parmCode', xtype: 'selectcombo'}
, 
	 {id: EN[2],hidden: true, name: EN[2],hiddenName: EN[2], fieldLabel:CN[2],url: 'pccCurrUserOrgProviderController.do',displayField: 'orgName',valueField: 'orgCode', xtype: 'selectcombo'}
, 
     {id: EN[3],hidden: true, name: EN[3], fieldLabel:CN[3], xtype: 'numberfield'} 		 
, 
     {id: EN[4],hidden: false, name: EN[4], fieldLabel:CN[4], xtype: 'textfield'}
     , 
	 {id: EN[5],hidden: false, name: EN[5],hiddenName: EN[5], fieldLabel:CN[5],url: 'parmInfoProvider.do?parmType=SUPPORTERS_PCC',displayField: 'parmName',valueField: 'parmCode', xtype: 'selectcombo'}
, 
     {id: EN[6],hidden: false, name: EN[6], fieldLabel:CN[6], xtype: 'numberfield'} 		 

];	

var fiscalYearField = new Ext.ux.seraph.DictCombo({url: 'parmInfoProvider.do?parmType=FINCAL_YEAR', displayField: 'parmName', valueField: 'parmCode'});	    	  
var fromAreaField = new Ext.ux.seraph.DictCombo({url: 'pccCurrUserOrgProviderController.do', displayField: 'orgName', valueField: 'orgCode'});	    	  
var supportersField = new Ext.ux.seraph.DictCombo({url: 'parmInfoProvider.do?parmType=SUPPORTERS_PCC', displayField: 'parmName', valueField: 'parmCode'});	    	  

var userColumns =[ 
    {header: CN[0], width: WD[0], sortable: true, dataIndex: EN[0], hidden: true, hideable: false,editor: {xtype: 'textfield'} },  
    {header: CN[1], width: WD[1], sortable: true, dataIndex: EN[1], hidden: true, hideable: false, renderer: Ext.ux.renderer.Combo(fiscalYearField), editor: fiscalYearField},  
    {header: CN[2], width: WD[2], sortable: true, dataIndex: EN[2], hidden: true, hideable: false, renderer: Ext.ux.renderer.Combo(fromAreaField), editor: fromAreaField},  
    {header: CN[3], width: WD[3], sortable: true, dataIndex: EN[3], hidden: true, hideable: false,editor: {xtype: 'textfield'} },  
    {header: CN[4], width: WD[4], sortable: true, dataIndex: EN[4], hidden: false, hideable: false,editor: {xtype: 'textfield'} },  
    {header: CN[5], width: WD[5], sortable: true, dataIndex: EN[5], hidden: false, hideable: false, renderer: Ext.ux.renderer.Combo(supportersField), editor: supportersField},  
    {header: CN[6], width: WD[6], sortable: true, dataIndex: EN[6], hidden: false, hideable: false,editor: {xtype: 'textfield'} }
];

// TODO: default xtype, width
var queryFields = [
	{text: CN[1]},           
    {
		xtype: 'selectcombo',
		id: '#fiscalYear',
       	name: EN[1],
       	hiddenName: EN[1],
		fieldLabel: CN[1],
		width: 90,
        url: 'parmInfoProvider.do?parmType=FINCAL_YEAR',
        displayField: 'parmName',
        valueField: 'parmCode'
	}
,  
	{text: CN[2]},           
    {
		xtype: 'selectcombo',
		id: '#fromArea',
       	name: EN[2],
       	hiddenName: EN[2],
		fieldLabel: CN[2],
		width: 90,
        url: 'pccCurrUserOrgProviderController.do',
        displayField: 'orgName',
        valueField: 'orgCode'
	}
 
];

var exportExcelFields={
	    text: '导出Excel',
	    iconCls: 'dataTableList-add-icon',
	    handler : exportExcel
};

function exportExcel(btn, ev) {	
	var fiscalYear=Ext.getCmp('#fiscalYear').getValue();
	var fromArea=Ext.getCmp('#fromArea').getValue();
	if(fromArea==''){
		alert('请选择地区！');
		return;
	}
	if(fiscalYear==''){
		alert('请选择年度！');
		return;
	}	
    var appWindow = window.open(URL.action+'?action=doExcel&&fiscalYear='+fiscalYear+'&&fromArea='+fromArea);    
    appWindow.focus();		
}

// 
var queryParms = [
    {name: EN[1], indicator: 'EXAMPLE_EQUALS'},   
    {name: EN[2], indicator: 'EXAMPLE_EQUALS'}  
];

Ext.onReady(function() {
	
    Ext.QuickTips.init();
    
    Ext.override(Ext.ux.seraph.FormEditorGrid,{
	    buildTbar : function(queryFields) {
	    	var gridSelf = this;
	    	return [{
	            text: '添加',
	            iconCls: 'dataTableList-add-icon',
	            scope: this,
	            handler : gridSelf.onCreate
		    }, '-', {
		        text: '修改',
		        iconCls: 'dataTableList-modify-icon',
	            scope: this,
		        handler: gridSelf.onUpdate
		    }, '-', {
	            text: '删除',
	            iconCls: 'dataTableList-delete-icon',
	            scope: this,
	            handler : gridSelf.onDelete
		    },'-',exportExcelFields,'-', queryFields, {
	        	text: '查询', 
	        	iconCls: 'dataTable-preview-icon', 
	        	handler : function() {
	        		gridSelf.loadData();
	        	}
	        }]
	     }	     
    });     
    
    var userGrid = new Ext.ux.seraph.FormEditorGrid({
        renderTo: 'user-grid',
        width: Ext.get("content").getWidth(),
        height: Ext.get("content").getHeight(),
    	storeFields: storeFields,
    	formFields: formFields,
    	queryFields: queryFields,
    	queryParms: queryParms,
    	columns: userColumns,
    	pk: PK,
    	url: URL
    });
    
    var currDate = new Date(); 
    Ext.getCmp('#fiscalYear').setValue(currDate.getFullYear()+1) ;  
    
	var fiscalYear = Ext.getCmp('#fiscalYear').getValue();
	Ext.getCmp(EN[1]).setValue(fiscalYear); 
	
    Ext.Ajax.request({
    	   url: 'baseLoginInfoController.do',
    	   success: function(response) {
    	   		var data = response.responseText.evalJSON();
    	   		Ext.getCmp('#fromArea').setValue(data.orgCode) ;
    	   },
    	   failure: Ext.emptyFn,
    	   params: {}
    }); 	    
});